var fceMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomereshop');
var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
var franceCustomerEshopStore;
var franceCustomerEshopGrid;
var franceCustomerEshopWindow;

var selectFranceCustomerEshop = function(selectFranceCustomerEshopCallback){
    if (!franceCustomerEshopWindow) {
        franceCustomerEshopWindow = new Ext.Window({
            title: message.get('message.combo.pleaseselect'),
            layout: 'fit',
            width: 900,
            height: 605,
            closeAction: 'hide',
            plain: true,
            modal: true,
            items: [{
                id: 'customerEshopPanel',
                region: 'center',
                bodyStyle: {
                    background: '#ffffff',
                    padding: '7px'
                },
                html: '<div id="franceCustomerEshopDiv"></div>'
            }]
        });
    }
    franceCustomerEshopWindow.show();
    
    if (franceCustomerEshopGrid){
		franceCustomerEshopStore.reload();
		return;
	}
    franceCustomerEshopStore = new Ext.data.Store({
                    url: '../../servlet/BiFranceCustomerEshopServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, ['index', 
                        'id', 
                        'accountNumber', 
                        'email', 
                        'title', 
                        'firstName', 
                        'lastName', 
                        'streetAddress', 
                        'phoneNumber', 
                        'postalCode', 
                        'city', 
                        'country',
                        'bTitle', 
                        'bFirstName', 
                        'bLastName', 
                        'bStreetAddress', 
                        'bPhoneNumber', 
                        'bPostalCode', 
                        'bCity', 
                        'bCountry']),
                    
                    remoteSort: true
                });
    
    franceCustomerEshopStore.setDefaultSort('id', 'desc');
    
    function renderSelectItem(value, p, record){
        return String.format('<a href="javascript: selectFranceCustomerEshopCallback(\'{0}\', \'{1}\', \'{2}\',\'{3}\', \'{4}\', \'{5}\',\'{6}\', \'{7}\', \'{8}\', \'{9}\', \'{10}\',\'{11}\', \'{12}\', \'{13}\',\'{14}\', \'{15}\', \'{16}\', \'{17}\', \'{18}\');franceCustomerEshopWindow.hide();"><img src="../../images/icons/arrow_rotate_clockwise.png" title="' + message.get('message.list.select') + '" /></a>', 
        		record.data.id, 
        		record.data.accountNumber,
        		record.data.email, 
        		record.data.title,
        		record.data.firstName, 
        		record.data.lastName, 
        		record.data.streetAddress,
        		record.data.phoneNumber, 
        		record.data.postalCode, 
        		record.data.city,
        		record.data.country,
        		record.data.bTitle,
        		record.data.bFirstName, 
        		record.data.bLastName, 
        		record.data.bStreetAddress,
        		record.data.bPhoneNumber, 
        		record.data.bPostalCode, 
        		record.data.bCity,
        		record.data.bCountry);
    }
	
	var franceCustomerEshopFilters = new Ext.grid.GridFilters({
		  		filters:[
				    {type: 'string',  dataIndex: 'accountNumber'},
				    {type: 'string',  dataIndex: 'title'},
				    {type: 'string',  dataIndex: 'firstName'},
				    {type: 'string',  dataIndex: 'lastName'},
				    {type: 'string',  dataIndex: 'streetAddress'},
				    {type: 'string',  dataIndex: 'phoneNumber'},
				    {type: 'string',  dataIndex: 'postalCode'},
				    {type: 'string',  dataIndex: 'city'},
				    {type: 'string',  dataIndex: 'country'}
				]});
	
	var franceCustomerEshopExpander = new Ext.grid.RowExpander({
        tpl : new Ext.XTemplate(
        		'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.address') + ':</b>&nbsp;&nbsp; {streetAddress}</p>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.phonemumber') + ':</b>&nbsp;&nbsp; {phoneNumber}</p>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>E-mail:</b>&nbsp;&nbsp; {email}</p><br/>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fcMessage.get('ui.francecustomer.addressbill') + '</b></p>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.title') + ':</b>&nbsp;&nbsp; {bTitle}&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.fname') + ':</b>&nbsp;&nbsp; {bFirstName}&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.lname') + ':</b>&nbsp;&nbsp; {bLastName}</p>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.postcode') + ':</b>&nbsp;&nbsp; {bPostalCode}&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.city') + ':</b>&nbsp;&nbsp; {bCity}&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.country') + ':</b>&nbsp;&nbsp; {bCountry}</p>',
				'<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.address') + ':</b>&nbsp;&nbsp; {bStreetAddress}&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <b>' + fceMessage.get('ui.francecustomereshop.phonemumber') + ':</b>&nbsp;&nbsp; {bPhoneNumber}</p>'
        )
    });
	
    // create the grid
    franceCustomerEshopGrid = new Ext.grid.GridPanel({
        title: fceMessage.get('ui.francecustomereshop.listtitle'),
        store: franceCustomerEshopStore,
        stripeRows: true,
        plugins: [franceCustomerEshopFilters, franceCustomerEshopExpander],
        height: 560,
        columns: [franceCustomerEshopExpander, {
            header: message.get('message.list.id'),
            width: 20,
            dataIndex: 'index',
            sortable: false
        }, {
            header: fceMessage.get('ui.francecustomereshop.account'),
            dataIndex: 'accountNumber',
            sortable: true
        }, {
            header: fceMessage.get('ui.francecustomereshop.title'),
            dataIndex: 'title',
            sortable: true
        },{
            header: fceMessage.get('ui.francecustomereshop.fname'),
            dataIndex: 'firstName',
            sortable: true
        },{
            header: fceMessage.get('ui.francecustomereshop.lname'),
            dataIndex: 'lastName',
            sortable: true
        },{
            header: fceMessage.get('ui.francecustomereshop.postcode'),
            dataIndex: 'postalCode',
            sortable: true
        },{
            header: fceMessage.get('ui.francecustomereshop.city'),
            dataIndex: 'city',
            sortable: true
        },{
            header: fceMessage.get('ui.francecustomereshop.country'),
            dataIndex: 'country',
            sortable: true
        }, {
            header: message.get('message.list.select'),
            width: 30,
            dataIndex: 'id',
            sortable: false,
            renderer: renderSelectItem
        }],
        viewConfig: {
            forceFit: true
        },
        loadMask: true,
        renderTo: 'franceCustomerEshopDiv',
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: franceCustomerEshopStore,
            displayInfo: true
        })
    });
    
    var startPage = getPrarmeterValue(window.location, 'startPage');
    var start;
    if (startPage == null || startPage == '') {
        start = 0;
    }
    else {
        start = (startPage - 1) * 20;
    }
    franceCustomerEshopStore.load({
        params: {
            start: start,
            limit: 20
        }
    });
}


